// Copyright (c) 2020 Presto Labs Pte. Ltd.
// Author: xguo

#pragma once

#include <string>

#include <rapidjson/document.h>

#include "coin/proto/coin_query.pb.h"

inline coin::proto::OrderErrorCode GetOrderErrorCode(const std::string& error_code) {
  using coin::proto::OrderErrorCode;
  auto result = coin::proto::OrderErrorCode::ORDER_UNKNOWN_ERROR;

  if (error_code == "0") {
    result = OrderErrorCode::ORDER_NO_ERROR;
  } else if (error_code == "51008") {
    result = OrderErrorCode::SUBMIT_ORDER_INSUFFICIENT_FUND;
  } else if (error_code == "51119") {
    result = OrderErrorCode::SUBMIT_ORDER_INSUFFICIENT_FUND;
  } else if (error_code == "51402") {
    result = OrderErrorCode::ORDER_FILLED_ALREADY;
  } else if (error_code == "51400") {
    result = OrderErrorCode::ORDER_NOT_FOUND;
  } else if (error_code == "51511") {
    result = OrderErrorCode::POST_ONLY_REJECT;
  } else if (error_code == "51401") {
    result = OrderErrorCode::ORDER_CANCELED_ALREADY;
  }

  return result;
}
